package com.wxy.service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import io.jsonwebtoken.Jwt;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

public class jwtServiceConfig {
	private static final String JWTTOKEN="123456Mszlu!@#$$";
	private static final int TIME=24*60*60*60*1000;
	public static String getToken(int id) {
		Map<String,Object> claims=new HashMap<String, Object>();
		claims.put("userId",id);
		JwtBuilder jwtBuilder=Jwts.builder()
				.signWith(SignatureAlgorithm.HS256,JWTTOKEN)
				.setClaims(claims)
				.setIssuedAt(new Date())
				.setExpiration(new Date(System.currentTimeMillis()+TIME));
		String token=jwtBuilder.compact();
		return token;
	}
	public static Map<String,Object> checkToken(String token){
		Jwt parse=Jwts.parser().setSigningKey(JWTTOKEN).parse(token);
		return (Map<String, Object>) parse.getBody();
	}
}
